package com.lge.pitchingcoins.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.view.Window;

import com.lge.pitchingcoins.R;
import com.lge.pitchingcoins.ui.clients.ClientsMainActivity;
import com.lge.pitchingcoins.ui.clients.ClientsMainActivityWithCocos;
import com.lge.pitchingcoins.ui.server.ServerMainActivity;
import com.lge.pitchingcoins.ui.server.ServerMainActivityWithCocos;
import com.lge.pitchingcoins.util.Util;

public class Welcome extends Activity {
    // Override Methods
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.welcome_intro);

        Handler handler = new Handler() {
            public void handleMessage(Message msg) {
                super.handleMessage(msg);

                DisplayMetrics dm = new DisplayMetrics();
                getWindowManager().getDefaultDisplay().getMetrics(dm);

                if (Util.isDeviceScreenIsLargerThanArgument(dm, 7.0)) {
                    startServerWithCocosActivity();
                } else {
                    startClientWithCocosActivity();
                }
                finish();
            }
        };

        handler.sendEmptyMessageDelayed(0, 3000);
    }       


    // Member Methods
    public void startServerActivity() {
        // TODO Start activity for the G Pad (A Server)
        Intent intent = new Intent(Welcome.this, ServerMainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        finish();
    }

    public void startClientActivity() {
        // TODO Start activity for Smart phones (Clients)
        Intent intent = new Intent(Welcome.this, ClientsMainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        finish();
    }

    public void startServerWithCocosActivity() {
        Intent intent = new Intent(Welcome.this, ServerMainActivityWithCocos.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        finish();
    }

    public void startClientWithCocosActivity() {
        Intent intent = new Intent(Welcome.this, ClientsMainActivityWithCocos.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        finish();
    }
}